//
//  userPhoneView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/2.
//

#import "userPhoneView.h"

@interface userPhoneView ()
@property (nonatomic ,strong) UIView * phoneview;
@property (nonatomic ,strong) UILabel * contentLab;
@property (nonatomic ,strong) UIImageView * imgview;
@property (nonatomic ,strong) UIButton * deleteBtn;
@property (nonatomic ,strong) UIImageView * backImg;


@end

@implementation userPhoneView
+ (instancetype)NewView{
    userPhoneView * view = [userPhoneView new];
    [view setupview];
    return view;
}
- (void)setupview{
    MJWeakSelf
    UIView * phoneview = [UIView new];
    self.phoneview = phoneview;
    [self addSubview:phoneview];
    phoneview.frame = CGRectMake(0, kwt(5), kwt(75), kwt(75));
    phoneview.addClickBlock(^{
        [weakSelf addimgClick];
    });
  
    
    UIImageView * tempimg = kimageView(@"add_people");
    self.backImg = tempimg;
    [phoneview addSubview:tempimg];
    [tempimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.offset(0);
    }];
    
   
    UIImageView * imgview = kimageView(@"");
    [DTKTool YJ:kwt(5) andView:imgview];
    self.imgview = imgview;
    imgview.addClickBlock(^{
        [weakSelf imgclick];
    });
    [self addSubview:imgview];
    [imgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(phoneview);
    }];
    
    UILabel * contentLab= [DTKTool labelWithText:@"0" andFont:kCFont(12) andTextColor:UIColor.whiteColor];
    self.contentLab= contentLab;
    [imgview addSubview:contentLab];
    contentLab.backgroundColor = [UIColor colorWithHexString:@"#303030" alpha:0.82];
    contentLab.textAlignment = NSTextAlignmentCenter;
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(kwt(20));
    }];
    
    UIButton * deleteBtn= [UIButton buttonWithType:0];
    self.deleteBtn = deleteBtn;
    deleteBtn.addimg([UIImage imageNamed:@"delete_photo"]).addTarget(self,@selector(BtnClick));
    [self addSubview:deleteBtn];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.offset(0);
        make.width.height.offset(kwt(23));
    }];
    [self deleteImg];
}
- (void)addimgClick{
    if(self.addImgBlock){
        self.addImgBlock();
    }
}
- (void)BtnClick{
    if(self.deleteBlock){
        self.deleteBlock();
    }
}
- (void)imgclick{
    if(self.openImgBlock){
        self.openImgBlock();
    }
}
///清空数据默认状态
- (void)deleteImg{
    self.deleteBtn.hidden = YES;
    self.imgview.hidden = YES;
    
}

- (void)setImgUrl:(NSString *)url{
    [self.imgview LZsetImageWithImagePath:url placeholderImage:@""];
    self.phoneview.hidden = YES;
    self.deleteBtn.hidden = NO;
    self.imgview.hidden = NO;
}

- (void)setImg:(UIImage *)img{
    self.imgview.image = img;
    self.deleteBtn.hidden = NO;
    self.imgview.hidden = NO;
}
- (void)setbackImg:(UIImage *)img{
    self.backImg.image = img;
}

- (void)setContent:(NSString *)content{
    self.contentLab.text = content;
}


@end
